<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/views/dashboard/mixins/resize.js'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
      title: {
      type: Object,
      default: {},
    },
    toolbox: {
      type: Object,
      default: {},
    },
    quotaIds: {
      type: Array,
      default: [],
    },
    legend: {
      type: Array,
      default: [],
    },
    data: {
      type: Array,
      default: [],
    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      series:[],
      indicator:[]
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
     
      this.quotaIds.forEach((item, index) => {
        if(this.data[this.quotaIds[index]]){
          this.series.push({
        name: this.legend[index],
        value: this.data[this.quotaIds[index]]
      });
        }
      
    });
    
    this.data.xAxis.forEach(item=>{
      this.indicator.push({"name":item})
    })
  
      this.chart.setOption({
        title: this.title,
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        toolbox: this.toolbox,
        radar: {
          radius: '66%',
          center: ['50%', '54%'],
          splitNumber: 8,
          splitArea: {
            areaStyle: {
              color: 'rgba(127,95,132,.3)',
              opacity: 1,
              shadowBlur: 45,
              shadowColor: 'rgba(0,0,0,.5)',
              shadowOffsetX: 0,
              shadowOffsetY: 15
            }
          },
          indicator:this.indicator
           
        },
        legend: {
          left: 'center',
          top:"10px",
          data: this.legend
        },
        series: [{
          type: 'radar',
          symbolSize: 0,
          areaStyle: {
            normal: {
              shadowBlur: 13,
              shadowColor: 'rgba(0,0,0,.2)',
              shadowOffsetX: 0,
              shadowOffsetY: 10,
              opacity: 1
            }
          },
          data: this.series,
          animationDuration: animationDuration
        }]
      })
    }
  }
}
</script>
